package com.jzlin.funhub.admin.service.question;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jzlin.funhub.admin.mapper.QuestionAnswerRepliesMapper;
import com.jzlin.funhub.admin.model.dto.QuestionAnswerPageDTO;
import com.jzlin.funhub.admin.model.dto.QuestionAnswerRepliesPageDTO;
import com.jzlin.funhub.admin.model.dto.QuestionPageDTO;
import com.jzlin.funhub.admin.model.entity.QuestionAnswer;
import com.jzlin.funhub.admin.model.entity.QuestionAnswerReplies;
import com.jzlin.funhub.admin.model.req.QuestionAnswerRepliesPageReq;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 问题回答嵌套表 服务实现类
 * </p>
 *
 * @author jzlin
 * @since 2025-07-07
 */
@Service
public class QuestionAnswerRepliesService extends ServiceImpl<QuestionAnswerRepliesMapper, QuestionAnswerReplies> {

    /**
     * 分页查询列表
     *
     * @param req 查询条件
     * @return
     */
    public IPage<QuestionAnswerRepliesPageDTO> queryPage(QuestionAnswerRepliesPageReq req) {
        Page<QuestionAnswerReplies> page = new Page<>(req.getCurrent(), req.getSize());
        QueryWrapper<QuestionAnswerReplies> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("source_answer_id", req.getSourceAnswerId());
        queryWrapper.orderByDesc("create_time");

        Page<QuestionAnswerReplies> queryResult = this.baseMapper.selectPage(page, queryWrapper);
        return queryResult.convert(QuestionAnswerRepliesPageDTO::convert);
    }
}
